package tests;

import static org.junit.Assert.*;

import game.Shot;

import java.util.Random;

import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ShotTest {
	Random random;
	Shot shot;

	@Before
	public void doBefore() {
		random = mock(Random.class);
		shot = new Shot(random);
	}

	@Test
	public void testNoPoints() {
		when(random.nextInt(6)).thenReturn(1).thenReturn(2).
								thenReturn(3).thenReturn(5).thenReturn(1);
		shot.doShot();
		assertEquals(0, shot.getScore());
	}
	
	// Desde aca.. resta en los thenReturn por 1
	@Test
	public void testOneDiceScoresOneHundredPoints() {
		when(random.nextInt(6)).thenReturn(0).thenReturn(3).
								thenReturn(3).thenReturn(5).thenReturn(1);
		shot.doShot();
		assertEquals(100, shot.getScore());
	}
	
	@Test
	public void testTwoOneDiceScoresTwoHundredPoints() {
		when(random.nextInt(6)).thenReturn(0).thenReturn(2).
								thenReturn(0).thenReturn(5).thenReturn(1);
		shot.doShot();
		assertEquals(200, shot.getScore());
	}
	
	@Test
	public void testThreeOneDicesScoresOneThousandPoints() {
		when(random.nextInt(6)).thenReturn(0).thenReturn(2).
		thenReturn(0).thenReturn(5).thenReturn(0);
		shot.doShot();
		assertEquals(1000, shot.getScore());
	}
	
	@Test
	public void testFourOneDicesScoresOneThousandAndOneHundredPoints() {
		when(random.nextInt(6)).thenReturn(0).thenReturn(2).
			thenReturn(0).thenReturn(0).thenReturn(0);
		shot.doShot();
		assertEquals(1100, shot.getScore());
	}
	
	@Test
	public void testOneFiveDiceScoresFiftyPoints()
	{
		when(random.nextInt(6)).thenReturn(4).thenReturn(2).
			thenReturn(3).thenReturn(2).thenReturn(3);
		shot.doShot();
		assertEquals(50, shot.getScore());
	}
	
	@Test
	public void testTwoFiveDiceScoresOneHundredPoints()
	{
		when(random.nextInt(6)).thenReturn(4).thenReturn(2).
			thenReturn(3).thenReturn(5).thenReturn(4);
		shot.doShot();
		assertEquals(100, shot.getScore());
	}
	
	@Test
	public void testThreeFiveDiceScoresFiveHundredPoints()
	{
		when(random.nextInt(6)).thenReturn(4).thenReturn(2).
			thenReturn(4).thenReturn(5).thenReturn(4);
		shot.doShot();
		assertEquals(500, shot.getScore());
	}
	
	@Test
	public void testFourFiveDiceScoresFiveHundredPoints()
	{
		when(random.nextInt(6)).thenReturn(4).thenReturn(2).
			thenReturn(4).thenReturn(4).thenReturn(4);
		shot.doShot();
		assertEquals(550, shot.getScore());
	}
	
	@Test
	public void testThreeOneAndOneFiveDiceScoresOneThousandAndFiftyPoints()
	{
		when(random.nextInt(6)).thenReturn(0).thenReturn(2).
			thenReturn(4).thenReturn(0).thenReturn(0);
		shot.doShot();
		assertEquals(1050, shot.getScore());
	}
	
	@Test
	public void testFourOneAndOneFiveDiceScoresOneThousandAndFiftyPoints()
	{
		when(random.nextInt(6)).thenReturn(0).thenReturn(0).
			thenReturn(4).thenReturn(0).thenReturn(0);
		shot.doShot();
		assertEquals(1150, shot.getScore());
	}
	
	@Test
	public void testThreeTwoDiceScoresTwoHundred()
	{
		when(random.nextInt(6)).thenReturn(1).thenReturn(2).
			thenReturn(3).thenReturn(1).thenReturn(1);
		shot.doShot();
		assertEquals(200, shot.getScore());
	}
	
	@Test
	public void testThreeThreeDiceScoresThreeHundred()
	{
		when(random.nextInt(6)).thenReturn(2).thenReturn(2).
			thenReturn(3).thenReturn(2).thenReturn(1);
		shot.doShot();
		assertEquals(300, shot.getScore());
	}
	
	@Test
	public void testThreeFourDiceScoresFourHundred()
	{
		when(random.nextInt(6)).thenReturn(3).thenReturn(3).
			thenReturn(3).thenReturn(2).thenReturn(1);
		shot.doShot();
		assertEquals(400, shot.getScore());
	}
	
	@Test
	public void testThreeSixDiceScoresSixHundred()
	{
		when(random.nextInt(6)).thenReturn(5).thenReturn(5).
			thenReturn(3).thenReturn(2).thenReturn(5);
		shot.doShot();
		assertEquals(600, shot.getScore());
	}
	
	@Test
	public void testTwoShotsWhenWeGet3OnesAndNextOneFive()
	{
		when(random.nextInt(6)).thenReturn(0).thenReturn(5).
			thenReturn(3).thenReturn(0).thenReturn(0).thenReturn(4).thenReturn(2);
		shot.doShot();
		int acumulated = shot.getScore();
		shot.doShot();
		acumulated += shot.getScore();
		assertEquals(1050, acumulated);
	}
	
	@Test
	public void testWhenTwoDiceShotsTwoTimeWeStillHaveOneDice()
	{
		when(random.nextInt(6)).thenReturn(0).thenReturn(5).
			thenReturn(3).thenReturn(0).thenReturn(0).thenReturn(4).thenReturn(2);
		shot.doShot();
		shot.getScore();
		shot.doShot();
		shot.getScore();
		assertEquals(1, shot.getAvailableDices());
	}
	
	@Test
	public void testWhenTwoDiceShotsThreTimesAndWeDontHaveDices()
	{
		when(random.nextInt(6)).thenReturn(0).thenReturn(5).
			thenReturn(3).thenReturn(0).thenReturn(0).thenReturn(4).thenReturn(2).thenReturn(0);
		shot.doShot();
		shot.getScore();
		shot.doShot();
		shot.getScore();
		shot.doShot();
		shot.getScore();
		assertEquals(0, shot.getAvailableDices());
	}
	
	@Test
	public void testWhenGetsFourSix()
	{
		when(random.nextInt(6)).thenReturn(5).thenReturn(5).
			thenReturn(5).thenReturn(2).thenReturn(5);
		shot.doShot();
		shot.getScore();
		assertEquals(2, shot.getAvailableDices());
	}
}
